package com.example.qjia.Presenters;

import com.example.qjia.Listener.LoginListener;
import com.example.qjia.model.LoginModel;
import com.example.qjia.model.LoginModelImp;
import com.example.qjia.ui.ViewInterface.LoginViewInterface;

/**
 * Created by ying_xiang on 2016/8/10.
 */
public class LoginPresenterImp implements LoginListener, LoginPresenter {
    private LoginViewInterface loginViewInterface;
    private LoginModel loginModel;

    public LoginPresenterImp(LoginViewInterface loginViewInterface) {
        this.loginViewInterface = loginViewInterface;
        loginModel=new LoginModelImp();
    }

    @Override
    public void success() {
        if (loginViewInterface !=null) {
            loginViewInterface.hideProgress();
            loginViewInterface.toNext();
        }
    }

    @Override
    public void failed(String msg) {
        if(loginViewInterface !=null) {
            loginViewInterface.hideProgress();
            loginViewInterface.showFail(msg);

        }
    }

    @Override
    public void onLogin(String username, String password) {
        if(loginViewInterface !=null){
            loginViewInterface.showProgress();

        }
        loginModel.login(username,password,this);

    }

    @Override
    public void ondestroy() {
        loginViewInterface =null;
        loginModel=null;

    }
}
